home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok58.lha
/
NPrint
/
txt
/
StringOps.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
6KB
|
272 lines
(**********************************************************************
:Program. StringOps.mod
:Contents. string operations, replaces the standard module "Strings".
:Author. Nicolas Benezan [bne]
:Address. Postwiesenstr. 2, D7000 Stuttgart 60
:Phone. 711/333679
:Copyright. Public Domain
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
:History. V1.0b [bne] 18.Apr.1989
**********************************************************************)
IMPLEMENTATION MODULE StringOps;
CONST
nul=CHAR(0);
PROCEDURE Append(VAR String:ARRAY OF CHAR;
Tail:ARRAY OF CHAR);
VAR
PosStr,PosTail:INTEGER;
BEGIN
PosTail:=0;
PosStr:=Length(String);
LOOP
IF PosStr>HIGH(String) THEN
EXIT
ELSIF (PosTail>HIGH(Tail)) OR (Tail[PosTail]=nul) THEN
String[PosStr]:=nul;
EXIT
END;
String[PosStr]:=Tail[PosTail];
INC(PosStr);
INC(PosTail);
END;
END Append;
PROCEDURE AppendChar(VAR String:ARRAY OF CHAR;
Char:CHAR);
VAR
Len:INTEGER;
BEGIN
Len:=Length(String);
IF Len<=HIGH(String) THEN
String[Len]:=Char;
IF Len<HIGH(String) THEN
String[Len+1]:=nul;
END;
END;
END AppendChar;
PROCEDURE Assign( Source:ARRAY OF CHAR;
VAR Destination:ARRAY OF CHAR);
VAR
Pos,Max:INTEGER;
BEGIN
Max:=HIGH(Source);
IF HIGH(Destination)<Max THEN
Max:=HIGH(Destination);
END;
Pos:=0;
LOOP
Destination[Pos]:=Source[Pos];
INC(Pos);
IF (Pos>Max) OR (Source[Pos]=nul) THEN
IF Pos<=HIGH(Destination) THEN
Destination[Pos]:=nul;
END;
EXIT
END;
END;
END Assign;
PROCEDURE CapChar(VAR Char:CHAR);
BEGIN
CASE Char OF
|"a".."z", "à".."ö", "ø".."þ": DEC(Char,32);
ELSE
END;
END CapChar;
PROCEDURE CapString(VAR String:ARRAY OF CHAR);
VAR
Pos:INTEGER;
BEGIN
Pos:=0;
WHILE (Pos<=HIGH(String)) AND (String[Pos]#nul) DO
CapChar(String[Pos]);
INC(Pos);
END;
END CapString;
PROCEDURE FindChar(String:ARRAY OF CHAR;
Char:CHAR;
Start:INTEGER):INTEGER;
VAR
Step:INTEGER;
BEGIN
IF Start<0 THEN
Start:=-Start;
Step:=-1;
ELSE
Step:=1;
END;
WHILE (Start<=HIGH(String)) AND (Start>=0) AND (String[Start]#nul) DO
IF String[Start]=Char THEN
RETURN Start
END;
INC(Start,Step);
END;
RETURN -1;
END FindChar;
PROCEDURE Concat( Head:ARRAY OF CHAR;
Tail:ARRAY OF CHAR;
VAR String:ARRAY OF CHAR);
BEGIN
Assign(Head,String);
Append(String,Tail);
END Concat;
PROCEDURE DeleteSubString(VAR String:ARRAY OF CHAR;
Start,Len:INTEGER);
BEGIN
INC(Len,Start);
WHILE Len<=HIGH(String) DO
String[Start]:=String[Len];
IF String[Len]=nul THEN
RETURN
END;
INC(Start);
INC(Len);
END;
IF Start<=HIGH(String) THEN
String[Start]:=nul;
END;
END DeleteSubString;
PROCEDURE FindSubString(String:ARRAY OF CHAR;
SubString:ARRAY OF CHAR;
Start:INTEGER):INTEGER;
VAR
Pos,Max:INTEGER;
BEGIN
Pos:=0;
Max:=HIGH(String)-Length(SubString)+1;
WHILE (String[Start]#nul) AND (Start<=Max) DO
LOOP
IF (Pos>HIGH(SubString)) OR (SubString[Pos]=nul) THEN
RETURN Start
END;
IF String[Start+Pos]#SubString[Pos] THEN
Pos:=0;
EXIT
END;
INC(Pos);
END;
INC(Start);
END;
RETURN -1;
END FindSubString;
PROCEDURE ShiftRight(VAR String:ARRAY OF CHAR;
Position, Distance: INTEGER);
VAR
Start,End:INTEGER;
BEGIN
End:=Length(String)+Distance;
IF End>HIGH(String) THEN
End:=HIGH(String);
END;
FOR Start:=End-Distance TO Position BY -1 DO
String[End]:=String[Start];
DEC(End);
END;
END ShiftRight;
PROCEDURE InsertSubString(VAR String:ARRAY OF CHAR;
SubString:ARRAY OF CHAR;
Position:INTEGER);
BEGIN
ShiftRight(String,Position,Length(SubString));
OverWrite(String,SubString,Position);
END InsertSubString;
PROCEDURE InsertChar(VAR String:ARRAY OF CHAR;
Char:CHAR;
Position:INTEGER);
BEGIN
ShiftRight(String,Position,1);
String[Position]:=Char;
END InsertChar;
PROCEDURE Length(String:ARRAY OF CHAR):INTEGER;
VAR
Len:INTEGER;
BEGIN
Len:=0;
WHILE (Len<=HIGH(String)) AND (String[Len]#nul) DO
INC(Len);
END;
RETURN Len;
END Length;
PROCEDURE OverWrite(VAR String:ARRAY OF CHAR;
Overlay:ARRAY OF CHAR;
Position:INTEGER);
VAR
Pos,Len:INTEGER;
BEGIN
Len:=Length(Overlay);
DEC(Len);
IF Position+Len>HIGH(String) THEN
Len:=HIGH(String)-Position;
END;
FOR Pos:=0 TO Len DO
String[Position]:=Overlay[Pos];
INC(Position);
END;
END OverWrite;
PROCEDURE SubString( Source:ARRAY OF CHAR;
VAR Destination:ARRAY OF CHAR;
Position,Len:INTEGER);
VAR
SrcLen,Pos:INTEGER;
BEGIN
SrcLen:=Length(Source);
IF Position+Len>SrcLen THEN
Len:=SrcLen-Position;
END;
FOR Pos:=0 TO Len-1 DO
Destination[Pos]:=Source[Position];
INC(Position);
END;
IF Len<=HIGH(Destination) THEN
Destination[Len]:=nul;
END;
END SubString;
PROCEDURE Compare(String1,String2:ARRAY OF CHAR):INTEGER;
VAR
Max,Max1,Max2,Res,Pos,Diff:INTEGER;
BEGIN
Max1:=HIGH(String1);
Max2:=HIGH(String2);
Res:=Max1-Max2;
IF Res<0 THEN
Max:=Max1;
ELSE
Max:=Max2;
END;
FOR Pos:=0 TO Max DO
Diff:=ORD(String1[Pos])-ORD(String2[Pos]);
IF (Diff#0) OR (String1[Pos]=nul) THEN
RETURN Diff
END;
END;
INC(Max);
IF (Res<0) AND (String2[Max]#nul) THEN
ELSIF (Res>0) AND (String1[Max]#nul) THEN
ELSE
RETURN 0;
END;
RETURN Res;
END Compare;
END StringOps.